unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, math;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Button11: TButton;
    Button12: TButton;
    Button13: TButton;
    Button14: TButton;
    Button15: TButton;
    Button16: TButton;
    Button17: TButton;
    Button18: TButton;
    Button19: TButton;
    Button20: TButton;
    Button21: TButton;
    Button22: TButton;
    Button23: TButton;
    Button24: TButton;
    Button25: TButton;
    Button26: TButton;
    Button27: TButton;
    Button28: TButton;
    Button29: TButton;
    Button30: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button16Click(Sender: TObject);
    procedure Button15Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure Button18Click(Sender: TObject);
    procedure Button17Click(Sender: TObject);
    procedure Button19Click(Sender: TObject);
    procedure Button20Click(Sender: TObject);
    procedure Button21Click(Sender: TObject);
    procedure Button30Click(Sender: TObject);
    procedure Button27Click(Sender: TObject);
    procedure Button28Click(Sender: TObject);
    procedure Button29Click(Sender: TObject);
    procedure Button23Click(Sender: TObject);
    procedure Button24Click(Sender: TObject);
    procedure Button25Click(Sender: TObject);
    procedure Button22Click(Sender: TObject);
    procedure Button26Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

function numclick(var dot: Integer; var x_in: real; var time: Integer;
  var num: Integer; var Label1: TLabel): Integer;

implementation

var
  i: Integer = 1;
  d: Integer = 0;
  x: real = 0;
  y: real = 0;
  c: Integer = 0;

{$R *.dfm}

function numclick(var dot: Integer; var x_in: real; var time: Integer;
  var num: Integer; var Label1: TLabel): Integer;

begin
  if (dot = 1) then
  begin
    x_in := x_in + Power(0.1, time) * num;
    inc(time);
  end
  else
    x_in := (x_in * 10) + num;
  Label1.Caption := FloatToStr(x_in);
end;

procedure TForm1.Button10Click(Sender: TObject); // 0
var
  number: Integer;
begin
  number := 0;
  numclick(d, x, i, number, Label1);
  Label1.Caption := FloatToStr(x);
end;

procedure TForm1.Button11Click(Sender: TObject); // add
begin
  Label2.Caption := Label1.Caption + '+';
  y := x;
  x := 0;
  c := 1;
  i := 0;
  Label1.Caption := FloatToStr(x);
end;

procedure TForm1.Button12Click(Sender: TObject); // -
begin
  Label2.Caption := Label1.Caption + '-';
  y := x;
  x := 0;
  c := 2;
  i := 0;
  Label1.Caption := FloatToStr(x);

end;

procedure TForm1.Button13Click(Sender: TObject);
begin
  Label2.Caption := Label1.Caption + '*';
  y := x;
  x := 0;
  c := 3;
  i := 0;
  Label1.Caption := FloatToStr(x);
end;

procedure TForm1.Button14Click(Sender: TObject);
begin
  Label2.Caption := Label1.Caption + '/';
  y := x;
  x := 0;
  c := 4;
  i := 0;
  Label1.Caption := FloatToStr(x);
end;

procedure TForm1.Button15Click(Sender: TObject); // dot
begin
  d := 1;
  i := 1;
end;

procedure TForm1.Button16Click(Sender: TObject); // clear
begin
  x := 0;
  d := 0;
  i := 0;
  Label1.Caption := FloatToStr(x);
  Label2.Caption := FloatToStr(x);
end;

procedure TForm1.Button17Click(Sender: TObject); // del
begin
  x := x / 10;
  x := trunc(x);
  Label1.Caption := FloatToStr(x);
end;

procedure TForm1.Button18Click(Sender: TObject); // =
begin
  Label2.Caption := Label2.Caption + FloatToStr(x);
  if (c = 1) then
  begin
    // Label2.Caption :=FloatToStr(y) +'+'+FloatToStr(x);
    y := y + x;
  end;

  if (c = 2) then
  begin
    // Label2.Caption :=FloatToStr(y) +'-'+FloatToStr(x);
    y := y - x;
  end;

  if (c = 3) then
  begin
    // Label2.Caption :=FloatToStr(y) +'*'+FloatToStr(x);
    y := x * y;
  end;

  if (c = 4) then
  begin
    // Label2.Caption :=FloatToStr(y) +'/'+FloatToStr(x);
    y := y / x;
  end;

  if (c = 5) then
  begin
    y := Power(y, x);
  end;
  Label1.Caption := FloatToStr(y);
end;

procedure TForm1.Button19Click(Sender: TObject);
begin
  y := sin(x);
  Label1.Caption := FloatToStr(y);
  Label2.Caption := 'sin(' + FloatToStr(x) + ')';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  number: Integer;
begin
  number := 1;
  numclick(d, x, i, number, Label1);
  // Label1.Caption := FloatToStr(x);
end;

procedure TForm1.Button20Click(Sender: TObject);
begin
  y := cos(x);
  Label1.Caption := FloatToStr(y);
  Label2.Caption := 'cos(' + FloatToStr(x) + ')';
end;

procedure TForm1.Button21Click(Sender: TObject);
begin
  y := tan(x);
  Label1.Caption := FloatToStr(y);
  Label2.Caption := 'tan(' + FloatToStr(x) + ')';
end;

procedure TForm1.Button22Click(Sender: TObject);
begin
  y := pi;
  Label1.Caption := FloatToStr(y);
  Label2.Caption := 'pi=';
end;

procedure TForm1.Button23Click(Sender: TObject);
begin
  y := exp(x);
  Label1.Caption := FloatToStr(y);
  Label2.Caption := 'exp' + FloatToStr(x);
end;

procedure TForm1.Button24Click(Sender: TObject);
begin
  y := ln(x);
  Label1.Caption := FloatToStr(y);
  Label2.Caption := 'ln' + FloatToStr(x);
end;

procedure TForm1.Button25Click(Sender: TObject);
begin
  y := log10(x);
  Label1.Caption := FloatToStr(y);
  Label2.Caption := 'lg' + FloatToStr(x);
end;

procedure TForm1.Button26Click(Sender: TObject);
var
  s, t: Integer;
begin
  s := trunc(x);
  t := 1;
  while (s > 0) do
  begin
    t := t * s;
    dec(s);
  end;
  Label1.Caption := IntToStr(t);
  Label2.Caption := FloatToStr(x) + '!';
end;

procedure TForm1.Button27Click(Sender: TObject);
begin
  y := Power(x, 2);
  Label1.Caption := FloatToStr(y);
  Label2.Caption := FloatToStr(x) + '^2';
end;

procedure TForm1.Button28Click(Sender: TObject);
begin
  y := x;
  x := 0;
  c := 5;
  Label1.Caption := FloatToStr(x);
  Label2.Caption := FloatToStr(y) + '^';
end;

procedure TForm1.Button29Click(Sender: TObject);
begin
  y := Power(10, x);
  Label1.Caption := FloatToStr(y);
  Label2.Caption := '10^' + FloatToStr(x);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  number: Integer;
begin
  number := 2;
  numclick(d, x, i, number, Label1);
  // Label1.Caption := FloatToStr(x);
end;

procedure TForm1.Button30Click(Sender: TObject);
begin
  y := sqrt(x);
  Label1.Caption := FloatToStr(y);
  Label2.Caption := 'sqrt(' + FloatToStr(x) + ')';
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  number: Integer;
begin
  number := 3;
  numclick(d, x, i, number, Label1);
  // Label1.Caption := FloatToStr(x);
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  number: Integer;
begin
  number := 4;
  numclick(d, x, i, number, Label1);
  // Label1.Caption := FloatToStr(x);
end;

procedure TForm1.Button5Click(Sender: TObject);
var
  number: Integer;
begin
  number := 5;
  numclick(d, x, i, number, Label1);
  // Label1.Caption := FloatToStr(x);
end;

procedure TForm1.Button6Click(Sender: TObject);
var
  number: Integer;
begin
  number := 6;
  numclick(d, x, i, number, Label1);
  // Label1.Caption := FloatToStr(x);
end;

procedure TForm1.Button7Click(Sender: TObject);
var
  number: Integer;
begin
  number := 7;
  numclick(d, x, i, number, Label1);
  // Label1.Caption := FloatToStr(x);
end;

procedure TForm1.Button8Click(Sender: TObject);
var
  number: Integer;
begin
  number := 8;
  numclick(d, x, i, number, Label1);
  // Label1.Caption := FloatToStr(x);
end;

procedure TForm1.Button9Click(Sender: TObject);
var
  number: Integer;
begin
  number := 9;
  numclick(d, x, i, number, Label1);
  // Label1.Caption := FloatToStr(x);
end;

end.
